package com.flying.learning.si.fs;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.integration.annotation.MessagingGateway;
import org.springframework.integration.config.EnableIntegration;
import org.springframework.integration.dsl.IntegrationFlow;
import org.springframework.integration.dsl.IntegrationFlows;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.junit4.SpringRunner;

//import org.springframework.integration.util.NoBeansOverrideAnnotationConfigContextLoader;

/**
 * @author Artem Bilan
 * @author Tim Ysewyn
 * @author Gary Russell
 * @author Oleg Zhurakousky
 * @since 5.0
 */
//@RunWith(SpringRunner.class)
//@DirtiesContext
@SpringBootApplication
public class IntegrationFlowTests {

    public static void main(String[] args) {
        SpringApplication.run(IntegrationFlowTests.class, args);
    }

    @Autowired
    private Exchanger exchanger;

//    @Test
    public void testDirectFlow() {
        System.out.println(this.exchanger.exchange("dream"));
    }

//    @MessagingGateway
    public interface Exchanger {
        //@Gateway@Payload
        String exchange(String out);
    }


    @Configuration
    @EnableIntegration
    public static class ContextConfiguration {

        @Bean
        public IntegrationFlow controlBusFlow() {
            return IntegrationFlows.from(Exchanger.class)
                    .<String>handle((p, h) -> p.toUpperCase())
                    .get();
        }
    }
}